package com.wzvtc.vsl.securitytool;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

import com.wzvtc.vsl.securitytool.ui.SettingItemView;

/**
 * Created by Vsl on 2015/3/25.
 */
public class Setup4Activity extends Activity {
    private SettingItemView siv_setup4_protect;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup4);

        sp = getSharedPreferences("config", MODE_PRIVATE);
        siv_setup4_protect = (SettingItemView) findViewById(R.id.siv_setup4_protect);

        siv_setup4_protect.setTitle("防盗保护");
        if (sp.getBoolean("protect", false)) {
            siv_setup4_protect.setChecked(true);
            siv_setup4_protect.setDesc("防盗保护已经打开");
        } else {
            siv_setup4_protect.setChecked(false);
            siv_setup4_protect.setDesc("防盗保护已经关闭");
        }

        siv_setup4_protect.setOnClickListener(new View.OnClickListener() {
            SharedPreferences.Editor editor = sp.edit();

            @Override
            public void onClick(View v) {
                if (siv_setup4_protect.isChecked()) {
                    editor.putBoolean("protect", false);

                    siv_setup4_protect.setChecked(false);
                    siv_setup4_protect.setDesc("防盗保护已经关闭");
                } else {
                    editor.putBoolean("protect", true);

                    siv_setup4_protect.setChecked(true);
                    siv_setup4_protect.setDesc("防盗保护已经打开");
                }
                editor.commit();
            }
        });
    }

    public void next(View view) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean("configed", true);
        editor.commit();

        Intent intent = new Intent(Setup4Activity.this, LostFindActivity.class);
        startActivity(intent);
        finish();
    }

    public void pre(View view) {
        Intent intent = new Intent(Setup4Activity.this, Setup3Activity.class);
        startActivity(intent);
        finish();
    }
}
